﻿// Decompiled with JetBrains decompiler
// Type: MG_Immediately.Helper
// Assembly: MG_SuperMiner, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4DA81FE3-ADC7-45B4-A911-3493B5D525DE
// Assembly location: E:\docs\Klei\OxygenNotIncluded\mods\Steam\2558070245\MG_SuperMiner.dll

using System;
using System.Reflection;

namespace MG_Immediately
{
  public static class Helper
  {
    public static object GetPrivateValue<T>(T obj, string fieldName) where T : class
    {
      try
      {
        FieldInfo field = typeof (T).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
        return field == (FieldInfo) null ? (object) null : field.GetValue((object) obj);
      }
      catch (Exception ex)
      {
        return (object) null;
      }
    }

    public static object GetPrivateStaticValue<T>(T obj, string fieldName) where T : class
    {
      try
      {
        FieldInfo field = typeof (T).GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic);
        return field == (FieldInfo) null ? (object) null : field.GetValue((object) obj);
      }
      catch (Exception ex)
      {
        return (object) null;
      }
    }

    public static void SetPrivateValue<T>(T obj, string fieldName, object value) where T : class
    {
      try
      {
        FieldInfo field = typeof (T).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
        if (field == (FieldInfo) null)
          return;
        field.SetValue((object) obj, value);
      }
      catch (Exception ex)
      {
      }
    }

    public static object CallPrivateMethod<T>(T obj, string methodName, object[] parameters = null) where T : class
    {
      try
      {
        MethodInfo method = typeof (T).GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
        return method == (MethodInfo) null ? (object) null : method.Invoke((object) obj, parameters);
      }
      catch (Exception ex)
      {
        return (object) null;
      }
    }
  }
}
